package com.powernode.service.impl;

import com.powernode.constant.Constants;
import jakarta.annotation.Resource;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageProperties;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Component;

import java.nio.charset.StandardCharsets;

@Component
public class DelayMessageService {

    @Resource
    private RabbitTemplate rabbitTemplate;

    public void sendDelayMessage(Integer orderId){
        // 创建消息属性
        MessageProperties messageProperties = new MessageProperties();
        messageProperties.setHeader("x-delay",Constants.DELAY_TIME);
        // 创建消息
        Message message = new Message(String.valueOf(orderId).getBytes(), messageProperties);
        // 发送消息
        rabbitTemplate.convertAndSend(Constants.EXCHANGE_DELAY_NAME,Constants.ROUTING_KEY_DELAY_NAME,message);
    }
}
